Use case: CRC calculation with default configuration

This use case describes how to calculate a CRC with the default configuration using HAL1 and HAL2.

Note

Once the CRC peripheral is initialized, the calculation process can be started without calling the global configuration function.

The default parameters are already set:

  • Default polynomial

  • Default CRC init value

  • Input reversibility none

  • Output reversibility disabled

Sequence diagram

CRC calculation with default configuration (polling mode)

  @startuml

  == Initialization ==

  "Application"->"CRC" : HAL_CRC_Init()
  "CRC" --> "Application" : hal status : HAL_OK

  == Process : Polling mode ==

  "Application"->"CRC" :  HAL_CRC_Calculate
  "CRC" --> "Application": hal status : HAL_OK

  @enduml

Code snippet

HAL1

HAL2

__IO uint32_t uwCRCValue = 0;
HAL_CRC_Init(&hcrc);
uwCRCValue = HAL_CRC_Calculate(&hcrc,
                               (uint32_t *)&aDataBuffer,
                               BUFFER_SIZE);
/* */
HAL_CRC_Init(&hCRC, HAL_CRC);
HAL_CRC_Calculate(pCRC,
                  &DataBuffer,
                  sizeof(uint32_t) * BUFFER_SIZE,
                  &CrcValue);

Key changes

  1. In HAL2, CRC calculation uses a handle initialized with an explicit instance (for example HAL_CRC_Init(&hCRC, HAL_CRC)).

  2. In HAL2, CRC APIs can return additional statuses (for example HAL_INVALID_PARAM and HAL_BUSY).

  3. The calculation call signature differs (buffer pointer and size in bytes, and output value provided as a parameter).